/////////////////////////////////////////////////////////////////////////////
// Name:        SettingsDlg.cpp
// Purpose:     
// Author:      Andrew (cod) Bulavinov
// Modified by: 
// Created:     06/01/2009 17:31:12
// RCS-ID:      
// Copyright:   
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "SettingsDlg.h"

////@begin XPM images
////@end XPM images

#include "AnimeCataloguerApp.h"

#include <wx/dirdlg.h>

/*!
 * SettingsDlg type definition
 */

IMPLEMENT_DYNAMIC_CLASS( SettingsDlg, wxDialog )


/*!
 * SettingsDlg event table definition
 */

BEGIN_EVENT_TABLE( SettingsDlg, wxDialog )

////@begin SettingsDlg event table entries
    EVT_BUTTON( ID_BTN_SRC_ADD, SettingsDlg::OnBTNSRCADDClick )

    EVT_BUTTON( ID_BTN_SRC_REMOVE, SettingsDlg::OnBTNSRCREMOVEClick )

    EVT_BUTTON( ID_BTN_FIELD_ADD, SettingsDlg::OnBTNFIELDADDClick )

    EVT_BUTTON( ID_BTN_FIELD_REMOVE, SettingsDlg::OnBTNFIELDREMOVEClick )

////@end SettingsDlg event table entries

END_EVENT_TABLE()


/*!
 * SettingsDlg constructors
 */

SettingsDlg::SettingsDlg()
{
    Init();
}

SettingsDlg::SettingsDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create(parent, id, caption, pos, size, style);
}


/*!
 * SettingsDlg creator
 */

bool SettingsDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin SettingsDlg creation
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();
////@end SettingsDlg creation
    return true;
}


/*!
 * SettingsDlg destructor
 */

SettingsDlg::~SettingsDlg()
{
////@begin SettingsDlg destruction
////@end SettingsDlg destruction
}


/*!
 * Member initialisation
 */

void SettingsDlg::Init()
{
////@begin SettingsDlg member initialisation
    m_SourcesList = NULL;
    m_Filters = NULL;
    m_FieldsList = NULL;
////@end SettingsDlg member initialisation
}


/*!
 * Control creation for SettingsDlg
 */

void SettingsDlg::CreateControls()
{    
////@begin SettingsDlg content construction
    SettingsDlg* itemDialog1 = this;

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemDialog1->SetSizer(itemBoxSizer2);

    wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(2, 2, 0, 0);
    itemBoxSizer2->Add(itemFlexGridSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Sources:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer3->Add(itemStaticText4, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
    itemFlexGridSizer3->Add(itemBoxSizer5, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString m_SourcesListStrings;
    m_SourcesList = new wxCheckListBox( itemDialog1, ID_SOURCES_LIST, wxDefaultPosition, wxSize(300, -1), m_SourcesListStrings, wxLB_SINGLE );
    itemBoxSizer5->Add(m_SourcesList, 1, wxGROW, 5);

    wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, wxID_STATIC, _("File Types:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer5->Add(itemStaticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    m_Filters = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _(".avi\n.mkv\n.mpeg\n.ogm\n.mp4"), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
    itemBoxSizer5->Add(m_Filters, 0, wxGROW|wxALL, 5);

    wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer5->Add(itemBoxSizer9, 0, wxALIGN_TOP|wxLEFT, 5);

    wxButton* itemButton10 = new wxButton( itemDialog1, ID_BTN_SRC_ADD, _("&Add"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer9->Add(itemButton10, 0, wxALIGN_CENTER_HORIZONTAL, 5);

    wxButton* itemButton11 = new wxButton( itemDialog1, ID_BTN_SRC_REMOVE, _("&Remove"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer9->Add(itemButton11, 0, wxALIGN_CENTER_HORIZONTAL, 5);

    wxStaticText* itemStaticText12 = new wxStaticText( itemDialog1, wxID_STATIC, _("Fields:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer3->Add(itemStaticText12, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
    itemFlexGridSizer3->Add(itemBoxSizer13, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString m_FieldsListStrings;
    m_FieldsList = new wxCheckListBox( itemDialog1, ID_FIELDS_LIST, wxDefaultPosition, wxSize(300, 100), m_FieldsListStrings, wxLB_SINGLE );
    itemBoxSizer13->Add(m_FieldsList, 1, wxGROW, 5);

    wxBoxSizer* itemBoxSizer15 = new wxBoxSizer(wxVERTICAL);
    itemBoxSizer13->Add(itemBoxSizer15, 0, wxALIGN_TOP|wxLEFT, 5);

    wxButton* itemButton16 = new wxButton( itemDialog1, ID_BTN_FIELD_ADD, _("&Add"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer15->Add(itemButton16, 0, wxALIGN_CENTER_HORIZONTAL, 5);

    wxButton* itemButton17 = new wxButton( itemDialog1, ID_BTN_FIELD_REMOVE, _("&Remove"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer15->Add(itemButton17, 0, wxALIGN_CENTER_HORIZONTAL, 5);

    wxStaticLine* itemStaticLine18 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
    itemBoxSizer2->Add(itemStaticLine18, 0, wxGROW|wxALL, 5);

    wxStdDialogButtonSizer* itemStdDialogButtonSizer19 = new wxStdDialogButtonSizer;

    itemBoxSizer2->Add(itemStdDialogButtonSizer19, 0, wxALIGN_RIGHT|wxALL, 5);
    wxButton* itemButton20 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer19->AddButton(itemButton20);

    wxButton* itemButton21 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer19->AddButton(itemButton21);

    itemStdDialogButtonSizer19->Realize();

////@end SettingsDlg content construction
}


/*!
 * Should we show tooltips?
 */

bool SettingsDlg::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap SettingsDlg::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin SettingsDlg bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end SettingsDlg bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon SettingsDlg::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin SettingsDlg icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end SettingsDlg icon retrieval
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_FIELD_ADD
 */

void SettingsDlg::OnBTNFIELDADDClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_FIELD_ADD in SettingsDlg.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_FIELD_ADD in SettingsDlg. 
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_FIELD_REMOVE
 */

void SettingsDlg::OnBTNFIELDREMOVEClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_FIELD_REMOVE in SettingsDlg.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_FIELD_REMOVE in SettingsDlg. 
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_SRC_ADD
 */

void SettingsDlg::OnBTNSRCADDClick( wxCommandEvent& event )
{
    wxDirDialog dlg(this, _("Select source directory"));
    if (dlg.ShowModal() == wxID_OK) {
        int pos = m_SourcesList->Append(dlg.GetPath());
        wxArrayString filters;
        for (int i = 0; i < m_Filters->GetNumberOfLines(); ++i) {
            if (!m_Filters->GetLineText(i).IsEmpty()) {
                filters.Add(m_Filters->GetLineText(i));
            }
        }
        if (wxGetApp().GetSources().Add(dlg.GetPath(), filters)) {
            m_SourcesList->Check(pos);
        } else {
            wxMessageBox(_("Failed to add source."), _("Failed"), wxCENTRE | wxICON_ERROR);
        }
    }
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_SRC_REMOVE
 */

void SettingsDlg::OnBTNSRCREMOVEClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_SRC_REMOVE in SettingsDlg.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_SRC_REMOVE in SettingsDlg. 
}

